#!/usr/bin/env python
# -*- coding: utf-8 -*-

import time
from multiprocessing import Queue,Process

q = Queue(5)

class Producer(Process):
    def __init__(self, limit=1):
        self.limit = limit
        super().__init__()
    def run(self):
        for i in range(self.limit):
            while q.full(): #队列满的时候不生产
                print('queue is full...')
                time.sleep(0.1)
            print('product msg-%d'%i)
            q.put('msg-%d'%i)



class Consumer(Process):
    def __init__(self):
        super().__init__()
    def run(self):
        while True:
            if not q.empty():
                print("consume %s"%q.get())
                time.sleep(0.5)

c = Consumer()
p = Producer(10)
c.start()
p.start()
c.join()
p.join()
